/**
 * VSR C2
 * File : OtherVSR.cpp
 * @author Vijay Rajvanshi
 */

#include "OtherVSR.h"

using namespace std;

/**
 * 
 * list all product names and cost in a given cart by ID
 */
void OtherVSR::cart_info(Menu m) {
    int selection = 0;
    // vector<Cart> carts = m.get_carts(); // unused
    vector<Cart_item> cart_items = m.get_cart_items();
    vector<Product> prods = m.get_prods();
    // vector<Cart_item> temp = m.get_cart_items(); //this vector is meant to keep track of items in each cart
    vector<Cart_item> temp; //this vector is meant to keep track of items in each cart
    
    cout << "Please enter a cart ID. We will display all products in that cart.";
    cout << endl;
    cin >> selection;

    for (int i = 0; i < cart_items.size(); ++i) {
        if (selection == cart_items[i].get_cart_id()) {
            temp.push_back(cart_items[i]);
        }
    }

    cout << endl << "Cart number " << selection << ": " << endl;

    for (int j = 0; j < temp.size(); j++) {
        cout << "\t Cart Item " << temp[j].get_cart_item_id() << endl;

        for (int k = 0; k < prods.size(); k++) {

            if (temp[j].get_prod_id() == prods[k].get_prod_id()) {
                cout << "\t" << "\t"
                        << temp[j].get_prod_qty() << " " << prods[k].get_prod_name() <<
                        " for $" << (prods[k].get_prod_price() * temp[j].get_prod_qty()) <<
                        endl;
            }
            // temp.clear();
        }
    }
}

/**
 * Add a New Cart Given a Customer and a Date

 */
void OtherVSR::add_new_cart(vector<Cart>& carts) {



    int day = 0;
	int month = 0;
    int year = 0;
    int cust_id = 0;

    cout << "Please enter your customer ID";
    cout << endl;
    cin >> cust_id;
    cout << endl << endl;

    cout << "Please enter the current month (enter January as 1, December as 12)";
    cout << endl;
    cin >> month;

    cout << endl << "Please enter the current day (for Jan 21, enter 21. for Jan 1, enter 1)";
    cout << endl;
    cin >> day;

    cout << endl << "Please enter the current year (for 2000, enter 2000):";
    cout << endl;
    cin >> year;
    cout << endl << endl;

	Chrono::Date cart_purchase_date(year, Chrono::Date::Month(month), day);

    carts.push_back(Cart((carts[carts.size() - 1].get_cart_id() + 1), cust_id, cart_purchase_date));

}

/**
 * Delete a cart Item from a cart
 * @param m Menu
 */
void OtherVSR::delete_cart_item(vector<Cart_item>&cart_items) {

    int cart_item_number;

    cout << "Please enter the number of the cart item you'd like to delete: ";
    cin >> cart_item_number;
    cout << endl;

    for (int i = 0; i < cart_items.size(); ++i) {
        if (cart_item_number == cart_items[i].get_cart_item_id()) {
            cart_items.erase(cart_items.begin() + i);
        }
    }

}
